<?php
namespace App\Http\Controllers\Download;
use Illuminate\Http\Request;
use App\Services\CommonService;
use Illuminate\Routing\Controller;
use App\Models\Order;

class IndexController extends Controller{

     /**
     * 导出签收凭证word
     */
    public function express(Request $request){
        
        $orderId = $request->input('orderId');
        $export = $request->input('export');
        if(!empty($orderId)){
            
            if($export){
                $file = Order::downloadWord($orderId);
                return response()->download($file);
                // var_dump($file);
                ob_clean();
            
                ob_start();
                
                $fp = fopen($file,"r");
                
                $file_size = filesize($file);
                
                $date=date("YmdHis");
                
                Header("Content-type:application/octet-stream");
                
                Header("Accept-Ranges:bytes");
                
                Header("Accept-Length:".$file_size);
                
                Header("Content-Disposition:attchment; filename=aa.docx");
                
                $buffer = 1024;
                
                $file_count = 0;
                
                while (!feof($fp) && $file_count < $file_size){
                
                    $file_con = fread($fp,$buffer);
                
                    $file_count += $buffer;
                    
                    // var_dump($file_con);
                    // echo $file_count."<br>";
                    echo $file_con;
                
                }
                
                fclose($fp);
                
                ob_end_flush();
            }
            
            
            return ReturnMsg(CommonService::HTTP_CODE_SUCCESS,'下载成功',['下载成功']);
            
        }else{
            
            return ReturnMsg(CommonService::HTTP_CODE_FAIL, '订单不存在');
            
        }
    }
    


    


}


